#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
struct node {
  int a, b, c;
};
node grow[maxn], pre[maxn];
int main() {
  int n, m, a, b, c;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b >> c;
    pre[i].a = pre[i - 1].a + a;
    pre[i].b = pre[i - 1].b + b;
    pre[i].c = pre[i - 1].c + c;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    int l = 1, r = n, ans = -1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (pre[mid].a >= a && pre[mid].b >= b && pre[mid].c >= c) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << ans << " ";
  }
}